<?php

use Illuminate\Database\Capsule\Manager as DB;

class ShareController extends CommonController
{
    protected $authExcept = [];

    public function indexAction()
    {
        $params = $this->get();
        $shares = shareModel::getList($params);
        json(['code' => 1, 'msg' => '获取成功', 'data' => $shares]);
    }

    public function addAction()
    {
        $spm = $this->getPost('spm');
        if (!empty($spm)) {
            DB::transaction(function () use ($spm) {
                $shareLog = shareModel::add($spm);
                Hook::emit('share_after', $shareLog);
            });
        }
        json(['code' => 1, 'msg' => '识别成功', 'data' => '']);
    }
}
